//
// Created by Administrator on 2021/5/11.
//
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    vector<int> decode(vector<int> &encoded) {
        auto n = encoded.size() + 1; // perm的长度
        int total = 0;
        for (int i = 1; i <= n; ++i) { // 1 到 n XOR结果
            total ^= i;
        }
        int odd = 0;
        for (int i = 1; i < encoded.size(); i += 2) {
            odd ^= encoded[i];
        }
        vector<int> perm(n, 0);
        perm[0] = odd ^ total;
        for (int i = 1; i < n; ++i) {
            perm[i] = perm[i - 1] ^ encoded[i - 1];
        }
        return perm;
    }


};


int main() {
    vector<int> encoded{6, 5, 4, 6};
    Solution sol;
    auto ans = sol.decode(encoded);
    for (const auto &x:ans) cout << x << endl;

    return 0;
}